package com.MyFirst.game2048;

import android.content.Context;
import android.view.Gravity;
import android.widget.FrameLayout;
import android.widget.TextView;

public class Card extends FrameLayout {

	public Card(Context context,int width) {
		super(context);
		
		label  = new TextView(getContext());
		label.setTextSize(32);
		label.setWidth(width);
		label.setBackgroundColor(0x33ffffff);
		label.setGravity(Gravity.CENTER);
		
		LayoutParams lp = new LayoutParams(-1,-1);
		lp.setMargins(10, 10, 0, 0);
		addView(label,lp);
		
		setNum(0);
	}
	
	private int num = 0;
	
	public int getColor(int num){
		int colorID=R.color.c0;
		switch(num){
		
			case 2: colorID=R.color.c2;break;
			case 4: colorID= R.color.c4;break;
			case 8: colorID=R.color.c8;break;
			case 16: colorID=R.color.c16;break;
			case 32: colorID= R.color.c32;break;
			case 64: colorID=R.color.c64;break;
			case 128: colorID= R.color.c128;break;
			case 256: colorID= R.color.c256;break;
			case 512: colorID= R.color.c512;break;
			case 1024: colorID= R.color.c1024;break;
			case 2048: colorID= R.color.c2048;break;
		}
		return colorID; 
	}
	
	public void setNum(int num){
		this.num=num;
		if (num<=0){
			label.setText("");
			label.setBackgroundResource(R.color.c0);
		}
		else{
			label.setText(getNum()+"");
			label.setBackgroundResource(getColor(num));
			System.out.println(getColor(num));
		}
	}
	
	public boolean equals(Card o) {
		return getNum()==o.getNum();
	}
	
	public int getNum(){
		return num;
	}
	
	private TextView label;
}
